package com.rjwh.dingdong.client.util;

import android.widget.TextView;

import java.util.Calendar;

public class SpecialCalendar {

    private static int daysOfMonth = 0; // 某月的天数
    private static int dayOfWeek = 0; // 具体某一天是星期几

    // 判断是否为闰年
    public static boolean isLeapYear(int year) {
        if (year % 100 == 0 && year % 400 == 0) {
            return true;
        } else if (year % 100 != 0 && year % 4 == 0) {
            return true;
        }
        return false;
    }

    // 得到某月有多少天数
    public static int getDaysOfMonth(boolean isLeapyear, int month) {
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                daysOfMonth = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                daysOfMonth = 30;
                break;
            case 2:
                if (isLeapyear) {
                    daysOfMonth = 29;
                } else {
                    daysOfMonth = 28;
                }

        }
        return daysOfMonth;
    }

    // 指定某年中的某月的第一天是星期几
    public static int getWeekdayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, 1);
        dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
        return dayOfWeek;
    }

    /**
     * 在点击gridView时，得到这个月中第一天的位置
     *
     * @return
     */
    public static int getStartPositon() {
        return dayOfWeek;
    }

    /**
     * 在点击gridView时，得到这个月中最后一天的位置
     *
     * @return
     */
    public static int getEndPosition() {
        return (dayOfWeek + daysOfMonth + 7) - 1;
    }


    /***
     * 显示星期
     *
     * @param @param day
     * @return void
     * @throws
     * @Title: showWeek
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @history 1.YYYY-MM-DD author: description:
     */
    public static void showWeek(TextView text, int day) {
        int week = day % 7 - 1 + dayOfWeek;
        switch (week) {
            case 1:
                text.setText("星期一");
                break;
            case 2:
                text.setText("星期二");
                break;
            case 3:
                text.setText("星期三");
                break;
            case 4:
                text.setText("星期四");
                break;
            case 5:
                text.setText("星期五");
                break;
            case 6:
                text.setText("星期六");
                break;
            case 7:
                text.setText("星期日");
                break;
            default:
                break;
        }

    }

}
